package tec.stan.ling.topo.graph.editpart;

import java.util.List;

import org.eclipse.draw2d.ChopboxAnchor;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.NodeEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;

import tec.stan.ling.core.top.model.Device;
import tec.stan.ling.core.top.model.Node;
import tec.stan.ling.topo.graph.figure.NodeFigure;

/**
 * 
 * 
 * @author Stan 张新潮
 * @since 2010-4-8
 */
public class DeviceEditPart extends AbstractGraphicalEditPart implements
		NodeEditPart {

	@Override
	protected IFigure createFigure() {
		return new NodeFigure((Node) getModel());
	}

	@Override
	protected void createEditPolicies() {
		// TODO Auto-generated method stub

	}

	// * --------------------------------
	// * Implement interface NodeEditPart
	// * --------------------------------

	@Override
	public ConnectionAnchor getSourceConnectionAnchor(
			ConnectionEditPart connection) {
		return new ChopboxAnchor(getFigure());
	}

	@Override
	public ConnectionAnchor getSourceConnectionAnchor(Request request) {
		return new ChopboxAnchor(getFigure());
	}

	@Override
	public ConnectionAnchor getTargetConnectionAnchor(
			ConnectionEditPart connection) {
		return new ChopboxAnchor(getFigure());
	}

	@Override
	public ConnectionAnchor getTargetConnectionAnchor(Request request) {
		return new ChopboxAnchor(getFigure());
	}

	@SuppressWarnings("unchecked")
	protected List getModelSourceConnections() {
		return ((Device) this.getModel()).getOutputLinks();
	}

	@SuppressWarnings("unchecked")
	protected List getModelTargetConnections() {
		return ((Device) this.getModel()).getInputLinks();
	}

}
